package com.cmcc.passenger.ui.profile.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.cmcc.passenger.data.AppRequest
import com.cmcc.passenger.data.entity.AddressBook
import com.cmcc.passenger.data.entity.FavoriteAddress
import com.cmcc.shared.utils.L
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class AddressBookViewModel : ViewModel() {
    val address = MutableLiveData<AddressBook>()
    val deleteAddress = MutableLiveData<String>()

    fun getAddress() {
        viewModelScope.launch(Dispatchers.Main) {
            try {
                val response = AppRequest.getInstance().getAddress()
                if (response.isSuccessful) {
                    val data = response.body()
                    address.value = data?.data
                }
            } catch (e: Exception) {
                L.d("e :" + e.message + "," + e.cause)
            }
        }
    }

    fun deleteAddress(id:String) {
        viewModelScope.launch(Dispatchers.Main) {
            try {
                val response = AppRequest.getInstance().deleteAddress(id)
                if (response.isSuccessful) {
                    val data = response.body()
                    deleteAddress.value = data?.data
                }
            } catch (e: Exception) {
                L.d("e :" + e.message + "," + e.cause)
            }
        }
    }



}